package com.omazan.nativeClient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.omazan.db.HandleAdmins;
import com.omazan.db.HandleCustomers;
import com.omazan.db.HandleEmployees;
import com.omazan.db.HandleUsers;
import com.omazan.db.models.Administrator;
import com.omazan.db.models.Customer;
import com.omazan.db.models.Employee;
import com.omazan.db.models.User;
import com.omazan.utils.OmazanException;

public class UserDeleteOperations {
	BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


	public void usertypeDeleteOperations() throws OmazanException, IOException {
int n=0;
		while (n==0) {
			System.out.println("DELETE:");
			System.out.println("1.Customer");
			System.out.println("2.Employee");
			System.out.println("3.Administrator");
			System.out.println("4.Exit to Previous Menu");
			String userInput = input.readLine();
			int operation = Integer.parseInt(userInput);
			switch (operation) {
			case 1:

				HandleCustomers hcust1 = new HandleCustomers();
				for (Customer eachCustomer : hcust1.readAllCustomersFromDB()) {
					System.out.println(eachCustomer.getCustomerId() + "|"
							+ eachCustomer.getFirstName() + " "
							+ eachCustomer.getLastName());
				}

				System.out.println("Choose Customer to delete:");
				int cusIdToDel = Integer.parseInt(input.readLine());

				int userIdDel = hcust1.readCustomerFromDBUsingId(cusIdToDel)
						.getUser().getUserId();

				hcust1.deleteUsingId(cusIdToDel);
				new HandleUsers().deleteUsingId(userIdDel);

				System.out.println("Customer ID:" + cusIdToDel
						+ " Deleted from Customer Database.");
				break;
			case 2:
				HandleEmployees hemp1 = new HandleEmployees();
				for (Employee eachEmployee : hemp1.readAllEmployeesFromDB()) {
					System.out.println(eachEmployee.getEmployeeId() + "|"
							+ eachEmployee.getFirstName() + " "
							+ eachEmployee.getLastName());
				}

				System.out.println("Choose Employee to delete:");
				int empIdToDel = Integer.parseInt(input.readLine());

				userIdDel = hemp1.readEmployeeFromDBUsingId(empIdToDel)
						.getUser().getUserId();

				hemp1.deleteUsingId(empIdToDel);
				new HandleUsers().deleteUsingId(userIdDel);

				System.out.println("Employee ID:" + empIdToDel
						+ " Deleted from Employee Database.");
				break;

			case 3:
				HandleAdmins hadm1 = new HandleAdmins();
				for (Administrator eachAdmin : hadm1.readAllAdminsFromDB()) {
					System.out.println(eachAdmin.getAdminId() + "|"
							+ eachAdmin.getFirstName() + " "
							+ eachAdmin.getLastName());
				}

				System.out.println("Choose Employee to delete:");
				int admIdToDel = Integer.parseInt(input.readLine());

				userIdDel = hadm1.readAdminFromDBUsingId(admIdToDel)
						.getUser().getUserId();

				hadm1.deleteUsingId(admIdToDel);
				new HandleUsers().deleteUsingId(userIdDel);

				System.out.println("Admin ID:" + admIdToDel
						+ " Deleted from Administrator Database.");
				break;
			case 4:
				n++;
				System.out.println("");
								break;
			default:
								break;
			}

		}

	}
}
